#include "Thread.hpp"
#include <vector>
#include <memory>
#include <unordered_map>
void func()
{
    while (true)
    {
        std::cout << "hello world" << std::endl;
        sleep(1);
    }
}

#define MX 4

void Count(int N)
{
    for (int i = 0; i < N; i++)
    {
        printf("i == %d\n", i);
        sleep(1);
    }
}

using Thread_ptr_t = MyPhread_Modle::Thread;
int main()
{
    // 如果要创建多线程呢?
    std::unordered_map<std::string, std::shared_ptr<Thread_ptr_t>> threads;

    for (int i = 0; i < MX; i++)
    {
        std::shared_ptr<Thread_ptr_t> td = std::make_shared<Thread_ptr_t>(func);
        threads[td->Name()] = td;
    }

    for (auto &thread : threads)
    {
        thread.second->Start();
    }

    for (auto &thread : threads)
    {
        thread.second->Join();
    }

    
    // MyPhread_Modle::Thread t(func);
    // t.Start();
    // t.Join();
    // MyPhread_Modle::Thread<int> t(Count,10);

    // t.Start();
    // sleep(5);
    // std::cout << "暂停" << std::endl;
    // t.Stop();
    // sleep(5);
    // t.Join();
    // std::cout << "等待成功" << std::endl;
    return 0;
}